<?php
class database
{
	const DB_LOCATION = 'sqlite:protected/buffboard.sqlite';
	
	static function getDBUser()
	{
		$dbName = "";
		$username = "";
		$password = "";
			
		$Brit1 = false;
		$Brit2 = false;
		$Brit3 = true;
		$Bri = false;
		$Chris = false;
		$Chris_local = false;
		$Mike = false;
		$Mike_test = false;
		
		if($Brit1)
		{
			$dbName = 'buffboard';
			$username = 'usr';
			$password = 'password';
		}
		elseif($Brit2)
		{
			$dbName = "kosbadb";
			$username = "kosba";
			$password = "Test123!";
		}
		elseif($Brit3)
		{
			$dbName = "buffboard";
			$username = "root";
			$password = "thebattleofbunkerhill";
		}
		elseif($Bri)
		{
			$dbName = 'buffboarddb';
			$username = 'brionna';
			$password = 'password';
		}
		elseif($Chris)
		{
			$dbName = "mcclaskc_test";
			$username = "mcclaskc_admin";
			$password = "Sak637800--";
		}
		elseif($Chris_local)
		{
			$dbName = "buffboard";
			$username = "root";
			$password = "Sak637800--";
		}
		elseif($Mike)
		{
			$dbName = 'buffboard';
			$username = 'root';
			$password = 'boomdoggy';
		}
		elseif($Mike_test)
		{
			$dbName = 'test_bb';
			$username = 'root';
			$password = 'boomdoggy';
		}
		
		return array('dbName' => $dbName, 'username' => $username, 'password' => $password);
	}
	
	static function getDB()
	{
		
		/*
		$creds = database::getDBUser();
		
		$DB = @mysqli_connect ("localhost", $creds['username'], $creds['password'], $creds['dbName']) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
		//die();
		
		return $DB;
		*/
		
		try {
			$db = new PDO(self::DB_LOCATION);
		} catch (PDOException $e) {
			die("Database Connection Failed: " . $e->getMessage());
		}
		
		$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		
		return $db;
		
	}
	
	static function getDBH()
	{
		$creds = database::getDBUser();
		
		$DBH = new PDO("mysql:host=localhost;dbname=".$creds['dbName'], $creds['username'], $creds['password']);  
		return $DBH;
	}
	
	static function getTestDBH()
	{
		$creds = database::getDBUser();
	
		$DBH = new PDO("mysql:host=localhost;dbname=".$creds['dbName'], $creds['username'], $creds['password']);
		return $DBH;
	}
	
	static function insertSQL($sql, $test = false)
	{
		if($test)
			$DBH = database::getDBH();
		else
			$DBH = database::getTestDBH();
		
		$stmt = $DBH->prepare($sql);
		
		try{
			$stmt->execute();
			return true;
		} catch (PDOException $e) {
			return false;
		}
		
		return true;
	}
	
	
}
?>